package com.zengqingfa.algorithm.cz.chapter02;

import java.util.Arrays;

/**
 * @author zengqingfa
 * @className SelectSort2
 * @description
 * @create 2021/8/6 19:26
 */
public class SelectSort2 {

    public static void main(String[] args) {
        int[] arr={3,1,2,5,7,4};
        sort(arr);
        System.out.println(Arrays.toString(arr));

    }

    public static void sort(int[] arr) {
        int minIndex,temp;
        for (int i = 0; i < arr.length; i++) {
            minIndex = i;
            for (int j = i + 1; j < arr.length; j++) {
               if(arr[minIndex]>arr[j]){
                   minIndex=j;
               }
            }
            //交换位置
            temp=arr[i];
            arr[i]=arr[minIndex];
            arr[minIndex]=temp;
        }
    }

}